﻿using System;
using System.Collections.Generic;
using System.Text;
using ElevatorLib;
using AnalysisLib;
using System.Diagnostics;
using System.Windows.Forms;

namespace ElevatorSIM
{
    public class Observer :IObserver
    {
        /// <summary>
        /// 统计人数
        /// </summary>
        private MainForm form = null;
        private IniFile ini = new IniFile(Application.StartupPath + "\\Sys.ini");

        public Observer(MainForm form)
        {
            this.form = form;

        }


        /// <summary>
        /// 实现观察者的Update
        /// </summary>
        /// <param name="p"></param>
        /// <param name="el"></param>
        public void Update(Person p, Elevator el)
        {
            this.run(p,el);
        }

        private void run(Person p, Elevator el)
        {
            Language language = new Language(ini.GetString("Language", "Type", "English"));
            switch (SimulationEngine.StateOfSimulation)
            {
                case SimulationState.BeginInit:
                    this.form.StatusLabel.Text = language.Begins_Initialize_Simulation_Environment;
                    break;
                case SimulationState.EndInit:
                    {
                        this.form.StatusLabel.Text = language.Initialization_Complete;                       
                    }
                    break;
                case SimulationState.Start:
                    this.form.StatusLabel.Text="开始仿真....." ;
                    break;
                case SimulationState.Pause:
                    this.form.StatusLabel.Text="开始停止....." ;
                    break;
                case SimulationState.Step:
                    this.form.StatusLabel.Text="单步调试....." ;
                    break;
                case SimulationState.GoOn:
                    this.form.StatusLabel.Text="仿真继续.....";
                    break;
                case SimulationState.Finish:
                    {
                        this.form.StatusLabel.Text = "仿真结束";                        
                        Debug.WriteLine("统计分析结果");
                        foreach (IAnalysis taget in SimulationEngine.AnalysisModules)
                        {
                            taget.Calculate();
                        }

                    }
                    break;
            }
        }

    }


}
